package JDBC;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo7 {
    public static void main(String[] args) throws SQLException {
        Connection conn = DBUtil.getConnection();
        Statement state = conn.createStatement();
        String sql = "SELECT COUNT(*) count,s.name "+
                     "FROM teacher t "+
                     "JOIN subject s ON t.subject_id=s.id "+
                     "GROUP BY s.name";
        ResultSet rs = state.executeQuery(sql);
        while (rs.next()){
            int num = rs.getInt("count");
            String name = rs.getString("s.name");
            System.out.println("教"+name+"的老师一共"+num+"人");
        }
    }
}
